#include "rspbase.h"

#include "Msg/Req/reqhead.h"

RspBase::RspBase()
{

}

void RspBase::ParseRspBody(const QString qsPkt)
{
    QStringList vFldAndRecs;
    QString qsBody = qsPkt;
    qsBody.remove(0, RSPHEAD_BYTES);

    vFldAndRecs = strutils::explode(GESS_FLD_SEPERATOR, qsBody);
    for (int i = 0; i < vFldAndRecs.size(); ++i)
    {
        QStringList lKV = strutils::explode(GESS_VAL_SEPERATOR, vFldAndRecs.at(i));
        if (lKV.size() == 2)
        {
            m_mapParameters[lKV.at(0)] = lKV.at(1);
        }
    }

    qDebug()<<"body:"<<qsBody << " kv size="<< m_mapParameters.size();
}

QString RspBase::GetQStringPara(const QString sKey)
{
    auto it = m_mapParameters.find(sKey);
    if (it != m_mapParameters.end())
        return it.value();
    else
        return "";
}

void RspBase::RemoveItem(const QString sKey)
{
    auto it = m_mapParameters.find(sKey);
    if (it != m_mapParameters.end())
        m_mapParameters.erase(it);
}
